package com.scqkxx.gamebox.activity.myself.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.avos.avoscloud.AVObject;
import com.bumptech.glide.Glide;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.databinding.ItemMyselfMainListBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * 个人主页列表
 * Created by hef on 2018/8/16.
 */

public class MyselfMainListAdapter extends RecyclerView.Adapter<MyselfMainListAdapter.ViewHolder> {
    private Context context;
    private List<AVObject> dataList = new ArrayList<>();

    public MyselfMainListAdapter(Context context, List<AVObject> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    @Override
    public MyselfMainListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_myself_main_list, parent, false);
        return new MyselfMainListAdapter.ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(MyselfMainListAdapter.ViewHolder holder, int position) {
        ItemMyselfMainListBinding binding = (ItemMyselfMainListBinding) holder.getBinding();
        AVObject avObject = dataList.get(position);

        Glide.with(context).load(avObject.getString("menuLogo")).into(binding.ivItemImg);
        binding.tvItemName.setText(avObject.getString("menuName"));

        binding.getRoot().setOnClickListener(v -> {
            String menuUrl = avObject.getString("menuUrl");
            if(TextUtils.isEmpty(menuUrl)) return;

        });
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private ViewDataBinding binding;

        public ViewHolder(ViewDataBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        public ViewDataBinding getBinding() {
            return this.binding;
        }
    }
}